﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace com.lover.astd.common.model
{
    public class Equipment : AsObject
    {
        private GoodsType _goodstype;
        /// <summary>
        /// 东西类型
        /// </summary>
        public GoodsType goodstype
        {
            get { return _goodstype; }
            set { _goodstype = value; }
        }
        private string _generalName;
        /// <summary>
        /// 使用者名字, 如果无人使用, 则为null
        /// </summary>
        public string GeneralName
        {
            get { return _generalName; }
            set { _generalName = value; }
        }
        public string EquipNameWithGeneral
        {
            get 
            {
                if (_generalName != null && _generalName != "") return String.Format("{0}({1})", _name, _generalName);
                else return _name;
            }
        }
        private EquipmentType _type;
        /// <summary>
        /// 装备类型
        /// </summary>
        public EquipmentType Type
        {
            get { return _type; }
            set { _type = value; }
        }
        private EquipmentQuality _quality;
        /// <summary>
        /// 品质
        /// </summary>
        public EquipmentQuality Quality
        {
            get { return _quality; }
            set { _quality = value; }
        }
        private bool _isFragment = false;
        /// <summary>
        /// 是否是碎片
        /// </summary>
        public bool IsFragment
        {
            get { return _isFragment; }
            set { _isFragment = value; }
        }
        private int _fragmentCount;
        /// <summary>
        /// 碎片个数, 如果是宝石, 表示当前级别宝石的个数
        /// </summary>
        public int FragmentCount
        {
            get { return _fragmentCount; }
            set { _fragmentCount = value; }
        }
        private int _totalFragmentCount;
        /// <summary>
        /// 合成整的总共需要多少碎片
        /// </summary>
        public int TotalFragmentCount
        {
            get { return _totalFragmentCount; }
            set { _totalFragmentCount = value; }
        }
        private int _valueNow;
        /// <summary>
        /// 当前数值
        /// </summary>
        public int ValueNow
        {
            get { return _valueNow; }
            set { _valueNow = value; }
        }
        private int _level;
        /// <summary>
        /// 强化级别
        /// </summary>
        public int Level
        {
            get { return _level; }
            set { _level = value; }
        }
        private int _enchantLevel;
        /// <summary>
        /// 魔化数值
        /// </summary>
        public int EnchantLevel
        {
            get { return _enchantLevel; }
            set { _enchantLevel = value; }
        }
        private bool _canUpgrade;
        /// <summary>
        /// 是否还可以升级
        /// </summary>
        public bool CanUpgrade
        {
            get { return _canUpgrade; }
            set { _canUpgrade = value; }
        }
        private int _upgradeCost;
        /// <summary>
        /// 升级所需费用
        /// </summary>
        public int UpgradeCost
        {
            get { return _upgradeCost; }
            set { _upgradeCost = value; }
        }
        private int _remainTime;
        /// <summary>
        /// 过期剩余时间, 如果=0, 表示已经拿到不会过期
        /// </summary>
        public int RemainTime
        {
            get { return _remainTime; }
            set { _remainTime = value; }
        }
        private bool _weaponEquiped;
        /// <summary>
        /// 兵器是否已装备
        /// </summary>
        public bool WeaponEquiped
        {
            get { return _weaponEquiped; }
            set { _weaponEquiped = value; }
        }
        private int _zeroStarNum;
        /// <summary>
        /// 0星兵器数
        /// </summary>
        public int ZeroStarNum
        {
            get { return _zeroStarNum; }
            set { _zeroStarNum = value; }
        }
        private int _curWeaponLevelLimit;
        /// <summary>
        /// 当前兵器最高星级
        /// </summary>
        public int CurWeaponLevelLimit
        {
            get { return _curWeaponLevelLimit; }
            set { _curWeaponLevelLimit = value; }
        }

        private bool _canEnchant;
        /// <summary>
        /// 是否可以继续魔化
        /// </summary>
        public bool CanEnchant
        {
            get { return _canEnchant; }
            set { _canEnchant = value; }
        }
        private int _enchantCost1;
        /// <summary>
        /// 少量魔化玉石量
        /// </summary>
        public int EnchantCost1
        {
            get { return _enchantCost1; }
            set { _enchantCost1 = value; }
        }
        private int _enchantCost2;
        /// <summary>
        /// 大量魔化玉石量
        /// </summary>
        public int EnchantCost2
        {
            get { return _enchantCost2; }
            set { _enchantCost2 = value; }
        }
        private int _enchantCost3;
        /// <summary>
        /// 海量魔化玉石量
        /// </summary>
        public int EnchantCost3
        {
            get { return _enchantCost3; }
            set { _enchantCost3 = value; }
        }

        public void fillValues(XmlNodeList nodes)
        { 
            foreach(XmlNode eqp_node in nodes)
            {
                // 不同的地方, 用的id不同, 强化/魔化/兵器 界面用的都是storeid, 仓库界面用的id, goodsid只有在没有id的情况下才能使用
                if (eqp_node.Name == "storeid" || eqp_node.Name == "goodsid")
                {
                    if(_id <= 0) Id = Int32.Parse(eqp_node.InnerText);
                }
                else if (eqp_node.Name == "id") Id = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "equipname" || eqp_node.Name == "name") Name = eqp_node.InnerText;
                else if (eqp_node.Name == "type") goodstype = (GoodsType)Enum.Parse(typeof(GoodsType), eqp_node.InnerText);
                else if (eqp_node.Name == "equiptype") Type = (EquipmentType)Enum.Parse(typeof(EquipmentType), eqp_node.InnerText);
                else if (eqp_node.Name == "quality") Quality = (EquipmentQuality)Enum.Parse(typeof(EquipmentQuality), eqp_node.InnerText);
                else if (eqp_node.Name == "attribute") ValueNow = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "coppercost") UpgradeCost = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "reallevel") Level = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "equiplv") Level = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "equiplevel")
                {
                    if(Level == 0) Level = Int32.Parse(eqp_node.InnerText);
                }
                else if (eqp_node.Name == "enchanting") EnchantLevel = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "remaintime") RemainTime = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "generalname") GeneralName = eqp_node.InnerText;
                else if (eqp_node.Name == "equiped") WeaponEquiped = eqp_node.InnerText == "1";
                else if (eqp_node.Name == "upgradeable") CanUpgrade = eqp_node.InnerText == "1";
                else if (eqp_node.Name == "enchantable") CanEnchant = eqp_node.InnerText == "true";
                else if (eqp_node.Name == "cost1") EnchantCost1 = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "cost2") EnchantCost2 = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "cost3") EnchantCost3 = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "chip") IsFragment = eqp_node.InnerText == "1";
                else if (eqp_node.Name == "goodsnum") FragmentCount = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "fnum") TotalFragmentCount = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "zerostarnum") ZeroStarNum = Int32.Parse(eqp_node.InnerText);
                else if (eqp_node.Name == "curlimit") CurWeaponLevelLimit = Int32.Parse(eqp_node.InnerText);
            }
        }
    }
    /// <summary>
    /// 装备类型, 普通攻击/普通防御/战法攻击/战法防御/策略攻击/兵符/策略防御
    /// </summary>
    public enum EquipmentType { 
        /// <summary>
        /// 普通攻击
        /// </summary>
        Sword = 1, 
        /// <summary>
        /// 普通防御
        /// </summary>
        Cloth = 2, 
        /// <summary>
        /// 战法攻击
        /// </summary>
        Horse = 3, 
        /// <summary>
        /// 战法防御
        /// </summary>
        Cloak = 4, 
        /// <summary>
        /// 策略攻击
        /// </summary>
        Book = 5, 
        /// <summary>
        /// 兵符
        /// </summary>
        Seal = 6, 
        /// <summary>
        /// 策略防御, 车
        /// </summary>
        Carriage = 7
    }
    /// <summary>
    /// 装备品质, 白/蓝/绿/黄/红/紫/超紫
    /// </summary>
    public enum EquipmentQuality { White=1, Blue=2, Green=3, Yellow=4, Red=5, Purple=6, SuperPurple=7 }
    /// <summary>
    /// 东西(没名字了, 就这么着吧, 就是所有东西)的类型, 1=? 2=? 3=兵器, 4=宝石, 5=玉佩(算饰品吧)
    /// </summary>
    public enum GoodsType { Things1=1, Things2=2, Weapon=3, Gem=4,  Decoration=5}
}
